#include "ros/ros.h"
#include "msgs_client_server/AddInt.h"

bool Handler(msgs_client_server::AddInt::Request& req, msgs_client_server::AddInt::Response& resp)
{
    int num1 = req.num1;
    int num2 = req.num2;

    if(num1 < 0 || num2 < 0)
    {
        ROS_ERROR("参数出现负数：%d, %d", num1, num2);
        return false;
    }
    ROS_INFO("接收到的参数为：%d, %d", num1, num2);
    int sum = num1 + num2;
    resp.sum = sum;
    ROS_INFO("结果为：%d", sum);
    return true;
}

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    ros::init(argc, argv, "server");
    ros::NodeHandle nh;
    ros::ServiceServer srv = nh.advertiseService("AddInt", Handler);

    ROS_INFO("AddInt 已经启动！");
    ros::spin();
    return 0;
}
